package com.hnas.common.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hnas.api.domain.RouteFinalValue;
import com.hnas.api.server.PostConnServer;

@Controller
@RequestMapping("/backend/common/postServer")
public class PostServerTest {
	
	@Autowired
	private PostConnServer postConnServerNew;
	
	private ObjectMapper objectMapper = new ObjectMapper();
	
	//根据证件信息获取卡相关信息 APP_GetCardCustInfoByIDNo
	@RequestMapping(value = "/GetCardCustInfoByIDNo", method = RequestMethod.POST)
	@ResponseBody
	public List<JSONObject> GetCardCustInfoByIDNo(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String sendData = request.getParameter("sendData");
		JSONObject in = objectMapper.readValue(sendData, JSONObject.class);
		List<JSONObject> fromList = postConnServerNew.getListResultData(in, RouteFinalValue.APP_GetCardCustInfoByIDNo, JSONObject.class);
		
		if(null != fromList){
			System.out.println("not null");
			for(JSONObject from :  fromList){
				System.out.println(from.getString("cardId"));
			}
		}else{
			System.out.println("null");
		}
		
		return fromList;
	}
	
	//根据卡号获取客户信息 APP_GetCustInfoByCardId
	@RequestMapping(value = "/GetCustInfoByCardId", method = RequestMethod.POST)
	@ResponseBody
	public JSONObject GetCustInfoByCardId(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String sendData = request.getParameter("sendData");
		JSONObject in = objectMapper.readValue(sendData, JSONObject.class);
		
		JSONObject from = postConnServerNew.getResultData(in, RouteFinalValue.APP_GetCustInfoByCardId, JSONObject.class);
		
		if(null != from){
			System.out.println("from not null");
			System.out.println("from IdentifyNo : " + from.getString("identifyNo"));
		} else {
			System.out.println("from null");
		}
		
		return from;
	}
	
	//发送微信模板消息 SendWxModelMsg
	@RequestMapping(value = "/SendWxModelMsg", method = RequestMethod.POST)
	@ResponseBody
	public JSONObject SendWxModelMsg(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String sendData = request.getParameter("sendData");
		JSONObject in = objectMapper.readValue(sendData, JSONObject.class);
		
		JSONObject from = postConnServerNew.getResultData(in, RouteFinalValue.SendWxModelMsg, JSONObject.class);
		
		if(null != from){
			System.out.println("from not null");
//			System.out.println("from IdentifyNo : " + from.getString("identifyNo"));
		} else {
			System.out.println("from null");
		}
		
		return from;
	}
}
